layui.use('table', function () {
    var table = layui.table;
    table.render({
        elem: '#test'
        , url: '/MailList/MaiPageList'
        , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
        }]
        , title: '用户数据表'
        , cols: [[
            { type: 'checkbox', fixed: 'left' }
            , { field: 'Id', title: 'ID', width: 150, fixed: 'left', unresize: true, sort: true }
            , { field: 'Name', title: '姓名', width: 200 }
            , { field: 'PosId', title: '职位Id', width: 150 }
            , { field: 'DepartId', title: '部门Id', width: 150 }
            , { field: 'Tel', title: '电话号码', width: 150 }
            , { field: 'Email', title: '邮箱', width: 200 }
            , { field: 'Pinyin', title: '拼音', width: 200 }
            , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 250 }
        ]]
        , page: true
        , id: 'testReload'
    });
    $("#checkbtn").click(function () {
        //获取复选框集合数据
        var checkStatus = table.checkStatus('testReload');
        var data = checkStatus.data;
        //获得where限制条件Id
        var codeId = "";
        if (data.length == 0) {
            layer.msg('请选择一行', {
                title: '提示框',
                icon: 0,
                time: 2000

            });
            return;
        };
        //遍历集合,拼接字符串
        for (var i in data) {
            if (i == data.length - 1) {
                codeId += data[i].Id
            } else {
                codeId += data[i].Id + ",";
            }
        };
        //温馨提示是否要删除
        $.ajax({
            url: "/MailList/MoreDel?id=" + codeId,
            type: "post",
            success: function (result) {
                if (result.success) {
                    layer.msg('批量删除成功!', { icon: 6, time: 1000 });
                    location.reload();//刷新页面 
                } else {
                    layer.msg('批量删除失败!', { icon: 6, time: 1000 });
                }
            }
        })
    })
    table.on('tool(test)', function (obj) {
        var data = obj.data;
        var id = data.Id;
        //console.log(obj)
        if (obj.event === 'del') {
            layer.confirm('真的删除行么', function (index) {
                $.ajax({
                    type: "post",
                    url: "/MailList/MailDel",
                    data: data,
                    success: function (responseResult) {
                        if (responseResult.success) {
                            layer.msg('删除成功!', { icon: 6, time: 1000 });
                            obj.del();
                            layer.close(index);
                            window.location.reload();//刷新页面
                        } else {
                            layer.msg('删除失败!', { icon: 6, time: 1000 });
                        }
                    }
                })
            });
        } else if (obj.event === 'edit') {
            var Id = data.Id;
            $.ajax({
                type: "post",
                url: "/MailList/Update?id=" + Id,
                success: function (responseResult) {
                    if (responseResult.success) {
                        window.location.href = "/Home/MailList_update";
                    } else {
                        layer.msg('编辑失败!', { icon: 6, time: 1000 });
                    }
                }
            })
        }

    });
})
//列表刷新
function TableReload() {
    var table = layui.table;
    //获取页面管理员名称和时间
    var obj_lis = document.getElementById("pinyin").getElementsByTagName("li");
    for (i = 0; i < obj_lis.length; i++) {
        obj_lis[i].onclick = function () {
            var username = this.innerHTML;
            alert(username);
            //上述方法等价于
            table.reload('testReload', {
                where: { //设定异步数据接口的额外参数，任意设
                    username: username,
                }
            });
        }
    }
};
//查询点击事件
$("li").click(function () {
    TableReload();
});








//查询点击事件
$("td").click(function () {
    /* var table = layui.table;*/
    //获取页面管理员名称和时间
   
    
    tds.each(function (i, data) {

       
            alert(this.id)
        
    })
})




        //上述方法等价于
/* table.reload('testReload', {
     where: { //设定异步数据接口的额外参数，任意设
         departid: departid,
     }
 });*/


